 const util = require('../../utils/util.js');
const Toast = require('../../utils/toast.js');
Page({
  data: {
    teacherinfo:'',
    teacherlessonlist:'',
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    currentTab: '0',
    lessoninfo: {},
    lessonid: 0,
    iscollect:0
  },
  onLoad: function (e) {
    this.getteacherinfo(e);
    // this.getindexlessonlist();
  },
  getteacherinfo: function (e) {
    let that = this;
    util.request('school/getteacherinfo',{id:e.id}).then(function (res){
      console.log(res);
      if (res.errno === 0) {
        that.setData({
          teacherinfo:res.data.teacherinfo,
          teacherlessonlist: res.data.teacherlessonlist,
          iscollect: res.data.iscollect
        });
      }
    });
  },
  changeTab(e) {
    console.log(e.currentTarget.dataset.id)
    this.setData({
      tabIndex: e.currentTarget.dataset.id
    })
  },
  toSearch() {
    wx.navigateTo({
      url: '/pages/search/search'
    })
  },
  navigateClick(e) {
    console.log(e.currentTarget.dataset.url)
    wx.navigateTo({
      url: e.currentTarget.dataset.url
    })
  },
  boutiqueTo(e) {
    wx.navigateTo({
      url: '/pages/special/special'
    })
  },
  toLessoninfo(e) {
    //console.log(e.currentTarget.dataset.id);
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/lessoninfo/lessoninfo?id=${id}`
    })
  },
  goClasslist(e) {
    console.log(e.currentTarget.dataset.title);
    let title = e.currentTarget.dataset.title;
    let classid = e.currentTarget.dataset.classid;
    wx.navigateTo({
      url: '/pages/classlist/classlist?title=' + title + '&classid=' + classid
    })
  },
  toFollow: function (e) {
    let that = this;
    let teacherid = e.currentTarget.dataset.id;
    //添加或是取消收藏
    util.request('school/getteacherfollow', {
      teacherid: teacherid
    })
      .then(function (res) {
        let _res = res;
        if (_res.errno == 0) {
          if (_res.data.type == 'add') {
            Toast('关注成功!', 'success')
            that.setData({
              iscollect: 1
            });
          } else {
            Toast('取消关注成功!', 'noicon')
            that.setData({
              iscollect: 0
            });
          }

        } else {

        }
      });
  },
})